package com.vv.tools.modules.sys.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.vv.tools.common.support.BaseModel;

import java.nio.charset.StandardCharsets;

import lombok.Getter;
import lombok.Setter;

import org.apache.commons.codec.digest.Sha2Crypt;

/**
 * <p>
 * 系统用户
 * </p>
 *
 * @author vv
 * @since 2025-02-19
 */
@Getter
@Setter
@TableName("sys_user")
public class User extends BaseModel {

    /**
     * 用户名
     */
    @TableField("username")
    private String username;

    /**
     * 密码
     */
    @TableField("password")
    private String password;

    /**
     * 盐
     */
    @TableField("salt")
    private String salt;

    /**
     * 昵称
     */
    @TableField("nickname")
    private String nickname;

    /**
     * 生日: yyyy-MM-dd
     */
    @TableField("birthday")
    private String birthday;

    /**
     * 性别(0-未知, 1-男, 2-女)
     */
    @TableField("gender")
    private Integer gender;

    /**
     * 邮箱
     */
    @TableField("email")
    private String email;

    /**
     * 手机
     */
    @TableField("phone")
    private String phone;

    /**
     * 状态(0：禁用, 1：正常)
     */
    @TableField("status")
    private Integer status;

    public boolean comparePassword(String password) {
        return this.password.equals(Sha2Crypt.sha256Crypt(password.getBytes(StandardCharsets.UTF_8), this.salt));
    }

}
